<?php

	include("include/common.php");
	include("include/header.php");

	if ($cat = $_GET['cat']) {
        $sql = "SELECT `name` AS `cat_name` FROM `cats` WHERE `id`='".$cat."'";
		list($cat_name) = mysql_fetch_array( mysql_query($sql) );
	}
?>
	<h2>Browse <?=$cat_name?></h2>
<?php

	$where = ($cat)	? "AND parent='".$cat."'" : "AND parent='0'";
    $sql = "SELECT * FROM `cats` WHERE status=1 ".$where." ORDER BY `id` DESC";
	$qr1 = mysql_query($sql) or die(mysql_error());

	if (mysql_num_rows($qr1) > 0) {
?>
		<?=$table2?>
		<tr>
<?php
		$i = 1;
		while ($row = mysql_fetch_object($qr1)) {
			if ($i == 1) {
?>
				<td width=50% valign=left><span class="Text1">
<?php       }

			echo '<a href="cat.php?cat='.$row->id.'" title="'.$row->name.'"><strong>'.$row->name.'</strong></a>';

			if ($i == 1) {
?>
				</td>
<?php          $i = 0;
			}
			$i++;
		} // END while loop
?>
		</tr>
		</table>
		<br />
<?php
	}
?>

<?php

	$where = ($cat) ? "AND cat='".$cat."'" : "";
    $sql = "SELECT users.*, bio.imagefile FROM `users` " .
           "LEFT JOIN `bio` ON bio.`user`=users.`uid` " .
           "WHERE `status`=1 ".$where." ORDER BY `uid` DESC";
	$qr1 = mysql_query($sql);
	$mid = (int)(mysql_num_rows($qr1) / 2);
	$i = 0;

	while ($row = mysql_fetch_object($qr1)) {
       $rs[$i]['uid']     = $row->uid;
       $rs[$i]['name']    = $row->username;
       $rs[$i]['age']     = $row->age;
       $rs[$i]['height']  = $row->height;
       $rs[$i]['city']    = $row->city;
       $rs[$i]['state']   = $row->state;
       $rs[$i]['image']   = $row->imagefile;

       $i++;
    } // END while loop

?>

<?=$table2?>
		<tr>
		  <td align=left>
            <table width="100%" border="0" cellPadding="3" cellSpacing="0">
<?php for ($x=0; $x<count($rs); $x+=5) { ?>
              <tr>
<?php    for ($y=0; $y<5; $y++) {
            $ls = $rs[$x+$y];
            if ($ls['name']) { ?>
                <td align="center" valign="top">
                  <a href="model.php?id=<?=$ls['uid']?>" class="nav"><img src="image.php?name=<?=$ls['image']?>" border=0 class="thumbnail" /></a><br />
                  <?=$ls['name'].", ".$ls['age'].", ".$ls['height']?><br />
                  <?=$ls['city'].", ".$ls['state']?>
                </td>
<?php       } else { ?>
                <td>&nbsp;</td>
<?php       }
         } ?>
              </tr>
<?php }	?>
            </table>
		  </td>
		</tr>
	</table>
	<br />
<?php
	include("include/footer.php");
?>